//定义需要的用的颜色
var COMMON_YELLOW = createColorWithRGBA(255, 153, 18, 255);
var COMMON_DARK = createColorWithRGBA(50, 51, 52, 255);

//定义BaseUrl
var staticSourceBaseUrl = "http://21xa689434.imwork.net:8090/";

//创建唯一的视图控制器
var mainVC = new ViewController(false, true);
var mainView = mainVC.view;
mainVC.title = 'VRT_WEB_PREVIEW';
mainView.backgroundColor = COMMON_DARK;

//定义一个自定义风格的Label
function displayLabelS1()
{
    Label.call(this);
    this.cornerRadius = 5 * kHeightScale;
    this.textAlignment = TextAlignmentCenter;
    this.textColor = whiteColor;
    this.fontSize = 40;
}

//创建一个图片视图
var bgImgView = new ImgView();
//imageUrl中如果http开头将直接作为链接请求、如果不包含(如下)将直接作为图片名称在本地寻找
bgImgView.imageUrl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556728832362&di=99f5847c7ac248047984304c88ac2ff6&imgtype=0&src=http%3A%2F%2Fm.iqiyipic.com%2Fu4%2Fimage%2F20180526%2F2d%2F91%2Fuv_5017933352_m_601_720_405.jpg";
//将该视图添加在主视图中
mainView.addSubView(bgImgView);
//对该视图进行布局
bgImgView.vrt_layout.topEqualToView(null).leftEqualToView(null).heightIs(235).widthRatioToView(null, 1);

var avatarView = new ImgView();
//设置视图圆角
avatarView.cornerRadius = 75.0/2.0 * kHeightScale;
mainView.addSubView(avatarView);
avatarView.vrt_layout.topSpaceToView(null, 30).centerXEqualToView(null).heightIs(75).widthEqualToHeight();

var nicknameLabel = new displayLabelS1();
mainView.addSubView(nicknameLabel);
nicknameLabel.vrt_layout.topSpaceToView(avatarView, 10).centerXEqualToView(null).heightIs(30).widthIs(200);

var ikuCodeLabel = new displayLabelS1();
mainView.addSubView(ikuCodeLabel);
ikuCodeLabel.vrt_layout.topSpaceToView(nicknameLabel, 10).leftEqualToView(nicknameLabel).heightIs(25).widthIs(90);

var fansLabel = new displayLabelS1();
mainView.addSubView(fansLabel);
fansLabel.vrt_layout.topSpaceToView(nicknameLabel, 10).leftSpaceToView(ikuCodeLabel, 20).heightIs(25).widthIs(90);

var verifyLabel = new displayLabelS1();
mainView.addSubView(verifyLabel);
verifyLabel.vrt_layout.topSpaceToView(fansLabel, 10).leftEqualToView(null).heightIs(25).widthRatioToView(bgImgView, 1);

var listHeader = new displayLabelS1();
//设置Label中显示的文字
listHeader.text = "TA的动态";
//设置文字的颜色
listHeader.textColor = COMMON_YELLOW;

mainView.addSubView(listHeader);
listHeader.vrt_layout.topSpaceToView(bgImgView, 5).leftEqualToView(null).heightIs(30).widthRatioToView(null, 1);


var dynamicDataArray = new Array();

//创建一个列表视图
var list = new List();

mainView.addSubView(list);
list.vrt_layout.topSpaceToView(listHeader, 0).leftEqualToView(null).heightIs(mainView.height() - listHeader.bottom()).widthRatioToView(null, 1);

avatarView.imageUrl = "http://114.55.84.37/anbao/img/dog.png";
nicknameLabel.text = "userModel.userNickName";
ikuCodeLabel.text = "Code";
verifyLabel.text = "无认证";
fansLabel.text = "粉丝 : " + 5;

//在视图不同阶段添加回调
mainVC.addCallBackViewDidLoad(function(){
});

//在视图即将显示时调用该回调
mainVC.addCallBackViewWillAppear(function(){
});
   
// mainVC.addCallBackViewDidAppear(function(){  
  //创建一个cell模版
  var cell = new Cell();
  //设置cell的固定高度、目前不支持高度自适应
  cell.setCellFixHeight(40 * kHeightScale);

  var dyContentLabel = new displayLabelS1();
  dyContentLabel.textColor = whiteColor;
  dyContentLabel.text = "FFF0";
  cell.addSubView(dyContentLabel);
  dyContentLabel.vrt_layout.topEqualToView(null).leftEqualToView(null).heightRatioToView(null, 0.9).widthRatioToView(null, 1);

  var offset = new View();
  offset.backgroundColor = COMMON_YELLOW;
  cell.addSubView(offset);
  offset.vrt_layout.topSpaceToView(dyContentLabel, 0).leftEqualToView(null).heightIs(1 * kHeightScale).widthRatioToView(null, 1);

  ////////////////////////////////////
  //创建一个cell模版
  var cell1 = new Cell();
  //设置cell的固定高度、目前不支持高度自适应
  cell1.setCellFixHeight(40 * kHeightScale);

  var dyContentLabel1 = new displayLabelS1();
  dyContentLabel1.textColor = whiteColor;
  dyContentLabel1.text = "FFF1";
  cell1.addSubView(dyContentLabel1);
  dyContentLabel1.vrt_layout.topEqualToView(null).leftEqualToView(null).heightRatioToView(null, 0.9).widthRatioToView(null, 1);

  var offset1 = new View();
  offset1.backgroundColor = COMMON_YELLOW;
  cell1.addSubView(offset1);
  offset1.vrt_layout.topSpaceToView(dyContentLabel1, 0).leftEqualToView(null).heightIs(1 * kHeightScale).widthRatioToView(null, 1);

  //////////////////////////////////
  var cell2 = new Cell();
  //设置cell的固定高度、目前不支持高度自适应
  cell2.setCellFixHeight(40 * kHeightScale);

  var dyContentLabel2 = new displayLabelS1();
  dyContentLabel2.textColor = whiteColor;
  dyContentLabel2.text = "FFF2";
  cell2.addSubView(dyContentLabel2);
  dyContentLabel2.vrt_layout.topEqualToView(null).leftEqualToView(null).heightRatioToView(null, 0.9).widthRatioToView(null, 1);

  var offset2 = new View();
  offset2.backgroundColor = COMMON_YELLOW;
  cell2.addSubView(offset2);
  offset2.vrt_layout.topSpaceToView(dyContentLabel2, 0).leftEqualToView(null).heightIs(1 * kHeightScale).widthRatioToView(null, 1);
  
  
  dynamicDataArray = [cell, cell1];
// });//mainVC.addCallBackViewDidAppear

mainVC.addCallBackViewWillDisappear(function(){
});

//提交这个视图控制器给本地做相关解析、
api_commitVC(mainVC);
nicknameLabel.addClick(function(){
    dynamicDataArray = [cell, cell1, cell2];
    list.reloadData(1, -1, -1, {"0":dynamicDataArray});
});
list.reloadData(1, -1, -1, {"0":dynamicDataArray});